package com.cershy.chatroomserver.controller;

import com.cershy.chatroomserver.annotation.UrlLimit;
import com.cershy.chatroomserver.annotation.Userid;
import com.cershy.chatroomserver.dto.UserDto;
import com.cershy.chatroomserver.entity.User;
import com.cershy.chatroomserver.service.UserService;
import com.cershy.chatroomserver.utils.ResultUtil;
import com.cershy.chatroomserver.vo.login.LoginVo;
import com.cershy.chatroomserver.vo.user.CreateUserVo;
import com.cershy.chatroomserver.vo.user.UpdateUserVo;
import io.jsonwebtoken.Jwts;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.security.Signature;
import java.util.Date;
import java.util.List;
import java.util.Map;
import io.jsonwebtoken.SignatureAlgorithm;

@RestController
@RequestMapping("/api/v1/user")
public class UserController {

    @Resource
    UserService userService;

    @GetMapping("/info")
    public Object getUserInfo(@RequestParam String userId) {
        UserDto userDto = userService.getUserById(userId);  // 修改为 UserDto 类型
        return ResultUtil.Succeed(userDto);
    }



    @UrlLimit
    @GetMapping("/list")
    public Object listUser() {
        List<UserDto> result = userService.listUser();
        return ResultUtil.Succeed(result);
    }

    @UrlLimit
    @GetMapping("/list/map")
    public Object listMapUser() {
        Map<String, UserDto> result = userService.listMapUser();
        return ResultUtil.Succeed(result);
    }

    @UrlLimit
    @GetMapping("/online/web")
    public Object onlineWeb() {
        List<String> result = userService.onlineWeb();
        return ResultUtil.Succeed(result);
    }

    @UrlLimit
    @PostMapping("/update")
    public Object updateUser(@Userid String userid, @RequestBody @Valid UpdateUserVo updateUserVo) {
        boolean result = userService.updateUser(userid, updateUserVo);
        return ResultUtil.ResultByFlag(result);
    }

}
